﻿using System.Linq;

using VirtualTournaments.DataAccess.SqlServer.DataProxies;

namespace VirtualTournaments.DataAccess.SqlServer.DataMappers
{
	internal sealed class JourneysDataMapper : AbstractDataMapper<SqlServer.Journey, Business.Tournaments.Journey, DataProxies.JourneyDataProxy>
	{
		#region Singleton implementation

		private static JourneysDataMapper _instance = null;
		private static object _instanceLocker = new object();

		private JourneysDataMapper() { }

		public static JourneysDataMapper Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (_instanceLocker)
					{
						if (_instance == null)
						{
							_instance = new JourneysDataMapper();
						}
					}
				}
				return _instance;
			}
		}

		#endregion

		internal override VirtualTournamentsDataContext GetDataContext()
		{
			return VirtualTournamentsDataContext.Instance;
		}

		internal override System.Data.Linq.Table<SqlServer.Journey> GetDataTable()
		{
			return GetDataContext().Journeys;
		}

		internal override Business.Tournaments.Journey DataObject2BusinessObject(SqlServer.Journey dataObject)
		{
			return new JourneyDataProxy(dataObject);
		}

		internal override void BusinessObject2DataObject(Business.Tournaments.Journey bizJourney, SqlServer.Journey dataJourney)
		{
			//TODO: untested
			dataJourney.Number = bizJourney.Number;
		}

		internal override void DataProxy2DataObject(JourneyDataProxy proxyJourney, SqlServer.Journey dataJourney)
		{
			//TODO: untested
			dataJourney.Number = proxyJourney.Number;
		}
	}
}
